//
//  MovieViewController.m
//  UI_元旦豆瓣
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "MovieViewController.h"
#import "MovieModel.h"
#import "MovieTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "MovieViewController2.h"

@interface MovieViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSArray *arrData;
@property (nonatomic, retain) NSMutableArray *modelArr;

@end

@implementation MovieViewController

- (void)dealloc{
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.view addSubview:_tableView];
    [_tableView release];
    self.navigationItem.title = @"电影";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0 green:0.4 blue:0.5 alpha:1];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    // 数据解析
    NSString *path = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"plist"];
    self.arrData = [NSArray arrayWithContentsOfFile:path];
    
    self.modelArr = [NSMutableArray array];
    for (NSDictionary *dic in _arrData) {
        MovieModel *model = [MovieModel moviemodel];
        [model setValuesForKeysWithDictionary:dic];
        [_modelArr addObject:model];
    }
    // 注册
    [self.tableView registerClass:[MovieTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
    UIImage *image = [UIImage imageNamed:@"/Users/dllo/Desktop/UI/UI_元旦豆瓣/UI_元旦豆瓣/Images/NavBar/btn_nav_list@2x.png"];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(buttonAction)];
    self.navigationItem.rightBarButtonItem = item;
 
}
// 新的排列方式
- (void)buttonAction{
    
}
// 协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _modelArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MovieTableViewCell *cell = [[MovieTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    cell.imageBack.image = [UIImage imageNamed:@"/Users/dllo/Desktop/UI/UI_元旦豆瓣/UI_元旦豆瓣/Images/ActivityList/bg_eventlistcell@2x.png"];
    MovieModel *model = [MovieModel moviemodel];
    model = _modelArr[indexPath.row];
    [cell.image sd_setImageWithURL:[NSURL URLWithString:model.images[@"large"]]];
    cell.lable.text = model.title;
    
    return cell;
}
// 点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MovieViewController2 *movie = [[MovieViewController2 alloc] init];
    movie.modeal = _modelArr[indexPath.row];
    [self.navigationController pushViewController:movie animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 170;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
